package real.comp;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

public class Comp1 {
    
    volatile static AtomicBoolean full = new AtomicBoolean(false);
    volatile static AtomicBoolean empty = new AtomicBoolean(true);

    //1. 实现生产者消费者模型
    public void consume() { 
       
    }

    public static void main(String[] args) {
        Thread comsumer = new Thread(() -> {
            while (!full.compareAndSet(true, false)) {
            }
            System.out.println("comsuming...");
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch(Exception e) {
                
            }
            empty.set(true);
        });
        Thread productor = new Thread(() -> {
            while (!full.compareAndExchange(false, true)) {

            }
            System.out.println("producting...");
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch(Exception e) {

            }
            empty.set(false);
        });

       
            comsumer.start();
            productor.start();
     
    }
}
